from time import sleep
from selenium import webdriver
# 打开浏览器-创建浏览器对象
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
# 打开浏览器
driver = webdriver.Chrome(executable_path='chromedriver.exe')
# 输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")
# driver = webdriver.Chrome()
# 放大浏览器
driver.maximize_window()
# 实例化并获取ActionChains类
action = ActionChains(driver)
# 定位用户名-在用户名上右击鼠标
username = driver.find_element_by_css_selector("#userA")
# 调用右击方法
cc = action.context_click(username)
# 执行
cc.perform()
# 上面三行合并为一行
cc = action.context_click(driver.find_element_by_css_selector("#userA")).perform()
# 输入用户名admin，暂停3秒
username2 = driver.find_element_by_css_selector("#userA").send_keys("admin")
sleep(3)
# 双击鼠标左键，选中admin
# action.double_click(username2).perform()
dc = action.double_click(username2)
dc.perform()
# 鼠标移动到‘注册按钮’，预期：按钮变色
button = driver.find_element_by_xpath("//p[5]/button")
action.move_to_element(button).perform()
# 间隔3秒，关关闭浏览
sleep(3)
# 退出浏览器
driver.close()